<nav class="navbar navbar-default">
  <div class="container-fluid">
    {% if download %}
    <ul class="nav navbar-nav nav-fixed m-t-0 m-b-0" style="display: flex">
      <li class="navbar-header"><a class="navbar-brand" href="/">经典</a></li>
      {% if prev and download == 'preview' %}
      <li class="name"><a href="{{prev['url']}}">{{prev['title']}}</a></li>
      {% end %}
      <li class="active name"><a href="#" class="no-pointer">{{title}}</a></li>
    </ul>
    {% else %}
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
              data-target="#bs-navbar-collapse" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/">{{handler.app.site['name']}}</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-navbar-collapse">
      <ul class="nav navbar-nav">
        {% if prev %}
        <li class="{{prev.get('cls','')}}"><a href="{{prev['url']}}">{{prev['title']}}</a></li>
        {% end %}
        {% if title %}
        <li class="active name"><a href="#" class="no-pointer">{{title}}</a></li>
        {% end %}
      </ul>
      <ul class="nav navbar-nav navbar-right">
        {% if current_user or themes %}
        <li class="dropdown">
          <a href="#" class="dropdown-toggle user" data-toggle="dropdown" role="button"
             aria-haspopup="true" aria-expanded="false">
            {% if current_user %} {{current_user['nickname']}} {% else %} 主题 {% end %}
            <span class="caret"></span></a>
          <ul class="dropdown-menu user">
            {% if current_user %}
            <li><a href="/user/profile">个人信息</a></li>
            <li><a href="/user/password">修改密码</a></li>
            {% if title != '用户管理' and current_user['username'] == 'admin' or len(current_user['username']) < 3 %}
            <li><a href="/users">用户管理</a></li>
            {% end %}
            <li role="separator" class="divider"></li>
            <li><a href="/api/user/logout?redirect=1">注销</a></li>
            <li><a href="/user/login?next={{request.path}}">切换用户</a></li>
            {% if themes %}<li role="separator" class="divider"></li>{% end %}
            {% end %}
            {% if themes %}
            <li><a id="theme-default" title="切换为普通外观">普通外观</a></li>
            <li><a id="theme-warm" title="切换为浅色外观、护眼色">护眼色</a></li>
            <li><a id="theme-dark" title="切换为深色外观">深色外观</a></li>
            {% end %}
          </ul>
        </li>
        {% end %}
        {% if not current_user and '/user/' not in request.path %}
        <li><a href="/user/login?next={{request.path}}">登录</a></li>
        {% end %}
      </ul>
    </div>
    {% end %}
  </div>
</nav>
<script>
  $('.nav-more').each((_, nav) => {
    const target = $('.nav-fixed,.collapse>.navbar-nav').first()
    while (nav.firstChild) {
      target.append(nav.firstChild)
    }
    nav.remove()
  })
</script>